﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace KetBanBonPhuong
{
    /// <summary>
    /// Summary description for AdminRole
    /// </summary>
    public class AdminRole
    {
        private int admin_id;

        public int Admin_id
        {
            get { return admin_id; }
            set { admin_id = value; }
        }

        private int role_id;

        public int Role_id
        {
            get { return role_id; }
            set { role_id = value; }
        }

        private DateTime created_date;

        public DateTime Created_date
        {
            get { return created_date; }
            set { created_date = value; }
        }

        private string description;

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public AdminRole()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public AdminRole(int admin_id, int role_id, DateTime created_date)
        {
            this.admin_id = admin_id;
            this.role_id = role_id;
            this.created_date = created_date;
        }

        public static DataTable GetAll()
        {
            DBHelp dbh = new DBHelp();
            DataTable dt = new DataTable();
            string cmd = "AdminRole_GetAll";
            dt = dbh.ExecuteDataTable(cmd, CommandType.StoredProcedure);
            return dt;
        }

        public static DataTable GetByAdminID(int ID)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@admin_id", ID);
            DataTable dt = new DataTable();
            string cmd = "select * from tbl_admin_role where admin_id = @admin_id";
            dt = dbh.ExecuteDataTable(cmd, CommandType.Text);
            return dt;
        }

        public static AdminRole GetInfo(int AdminID, int RoleID)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@admin_id", AdminID);
            dbh.AddParameter("@role_id", RoleID);
            AdminRole ar = new AdminRole();
            string cmd = "AdminRole_GetInfo";
            SqlDataReader sdr = dbh.ExecuteReader(cmd, CommandType.StoredProcedure);
            if (sdr.Read())
            {
                ar.Admin_id = sdr.GetInt32(0);
                ar.Role_id = sdr.GetInt32(1);
                if (!sdr.IsDBNull(1))
                    ar.Created_date = sdr.GetDateTime(2);
                if (!sdr.IsDBNull(2))
                    ar.Description = sdr.GetString(3);
            }
            return ar;
        }

        public static void Insert(AdminRole ar)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@admin_id", ar.Admin_id);
            dbh.AddParameter("@role_id", ar.Role_id);
            dbh.AddParameter("@created_date", ar.Created_date);
            dbh.AddParameter("@description", ar.Description);
            string cmd = "AdminRole_Insert";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }

        //public static void Update(AdminRole ar)
        //{
        //    DBHelp dbh = new DBHelp();
        //    dbh.AddParameter("@admin_id", ar.Admin_id);
        //    dbh.AddParameter("@role_id", ar.Role_id);
        //    dbh.AddParameter("@created_date", ar.Created_date);
        //    dbh.AddParameter("@description", ar.Description);
        //    string cmd = "AdminRole_Update";
        //    dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        //}

        public static void Delete(int AdminID, int RoleID)
        {
            DBHelp dbh = new DBHelp();
            dbh.AddParameter("@admin_id", AdminID);
            dbh.AddParameter("@role_id", RoleID);
            string cmd = "AdminRole_Delete";
            dbh.ExecuteNonQuery(cmd, CommandType.StoredProcedure);
        }
    }
}